package vip.xiaonuo.bi.modular.dataset.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.bi.modular.dataset.param.DataSetAddParam;
import vip.xiaonuo.bi.modular.dataset.service.DatasetService;
import vip.xiaonuo.common.pojo.CommonResult;

import javax.annotation.Resource;

/**
 * 数据源分类表控制器
 *
 * @author 顾育司
 * @date  2023/12/15 12:09
 */
@Api(tags = "数据集列表控制器")
@ApiSupport(author = "SNOWY_TEAM", order = 3)
@RestController
@Validated
public class DataSetListController {
    @Resource
    DatasetService datasetService;


    @ApiOperation("数据集-详情")
    @GetMapping("/bi/dataset/get")
    public CommonResult getById(Long id) {
        return  CommonResult.data(datasetService.getById(id));
    }

    @ApiOperation("数据集-添加")
    @PostMapping(value = "/bi/dataset/add",consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
    public CommonResult add(@RequestParam(value = "file", required = false) MultipartFile file,  DataSetAddParam dataSetAddParam) {
        datasetService.addDataset(dataSetAddParam,file);
        return  CommonResult.ok();
    }

    @ApiOperation("数据集-id删除")
    @PostMapping(value = "/bi/dataset/deleteById")
    public CommonResult deleteById(Long id) {
        datasetService.removeById(id);
        return  CommonResult.ok();
    }

    @ApiOperation("数据集-预览数据")
    @GetMapping("/bi/dataset/preView")
    public CommonResult getPreView (Long id,Integer Limit) {
        return  CommonResult.data(datasetService.getPreView(id,Limit));
    }

    @ApiOperation("数据集-列信息")
    @GetMapping("/bi/dataset/getColInfo")
    public CommonResult getColInfo (Long id) {
        return  CommonResult.data(datasetService.getColInfo(id));
    }



}